/*
 * 1539. 移动零
 * 给一个数组 nums 写一个函数将 0 移动到数组的最后面，非零元素保持原数组的顺序
 * https://www.lintcode.com/problem/move-zeroes/description
 * 
 * 样例
 * 给出 nums = [0, 1, 0, 3, 12], 调用函数之后, nums = [1, 3, 12, 0, 0].
 * 
 * 2018.06.17 @jeyming
 */
package move_zeroes_1539;

public class Move_zeroes_1539 {
	/**
	 * @param nums: an integer array
	 * @return: nothing
	 */
	public void moveZeroes(int[] nums) {
		// write your code here
		int cnt = 0;
		int cntZero = 0;
		for(int i = 0; i < nums.length; ++i) {
			if(nums[i] != 0) {
				nums[cnt++] = nums[i];
			} else {
				++cntZero;
			}
		}
		for(int i = 0; i < cntZero; ++i) {
			nums[cnt++] = 0;
		}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
